<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <script src="../React-js/react.development.js" type="text/javascript"></script>
    <script src="../React-js/react-dom.development.js" type="text/javascript"></script>
    <script src="../React-js/babel.min.js" type="text/javascript"></script>
    <div id="test"></div>
    <script type="text/babel">
        class Father extends React.Component{
            state = {
                val:true
            }
            change = ()=>{
                this.setState({val:!this.state.val})
            }
            render(){
                return (
                    <div>
                        <h2>father</h2>
                        <Son valName={this.state.val?'son':'father'}/>
                        <button onClick={this.change}>改变</button>
                   </div>
                )
            }
        }
        class Son extends React.Component{
            // 组件再第一次挂载后 接受新的props
            componentWillReceiveProps(){
                console.log('componentWillReceiveProps');
            }
            render(){
                return (
                    <div>
                        <h2>son</h2>
                        <div>{this.props.valName}</div>
                    </div>
                )
            }
        }
        ReactDOM.render(<Father/>,document.querySelector('#test'))
    </script>
</body>
</html>